#import "MEnvironment.h"
#include "mathlink.h"


@implementation MEnvironment

+ (id) environment
{
	return [[[MEnvironment alloc] initWithEnvironment: MLInitialize(NULL) close: YES] autorelease];
}

- (id) initWithEnvironment: (void*) environment close: (BOOL) close
{
	self = [super init];
	_env = environment;
	_close = close;
	return self;
}

- (void) dealloc
{
	if(_close)
		MLDeinitialize((MLEnvironment) _env);
	[super dealloc];
}

- (void*) environment
{
	return _env;
}

- (NSString*) errorString: (long) error
{
	return [NSString stringWithUTF8String: MLErrorString((MLEnvironment)_env, error)];
}

@end